# -*- coding: utf-8 -*-

# -------------------------------
# Author    : linlingwei
# Email     : 951035650@qq.com
# File Name : fEar.py
# Date      : 2019/9/16 
# IDE       : PyCharm
# Version   : 1.0.1
# -------------------------------
import traceback
import maya.cmds as mc
import maya.mel as mel

import configs.constants.facial_constant as fc
import configs.constants.global_constant as gc
import configs.constants.suffix_constant as sc
import configs.constants.nodeType_constant as ntc
import configs.constants.attribute_constant as ac

import scripts.commonCmds as con
reload(con)
import scripts.curveCmds as cr
import scripts.deformerCmds as dc
reload(dc)
import rig.facial.fCore as fCore
reload(fCore)

class Ear(fCore.FacialCore):
    def __init__(self):
        super(Ear,self).__init__(fc.ear)
        self.transform_init()
        
    def create(self):
        try:
            self.earloc()
            self.hide_doDelete()
        except:
            traceback.print_exc()
        return
    
    def earloc(self):
        
        jot_list = list()
        for lr in [fc.lf,fc.rt]:
            tmp_loc = mc.ls(con.lname(lr,fc.ear,"*",sc.sLoc),fl=True)
            pat = cr.objToControl(tmp_loc[0],name = con.lname(lr,fc.ear,fc.root),colorId=17,ctrlShape="cube")
            cr.scaleXYZ(pat,0.3)
            pat_j = mc.createNode(ntc.tJoint,name=con.lname(lr,fc.ear,fc.root,sc.sJot))
            jot_list.append(pat_j)
            mc.setAttr(pat_j + ".radius", 0.1)
            mc.parent(pat_j, pat, r=True)
            mc.parent(pat,self.local_toParent)
            con.emptyGroup(pat)
            jgrp = con.emptyGroup(pat_j)
            mc.parent(jgrp[0], self.local_static)

            for i,tl in enumerate(tmp_loc):
                ctr = cr.objToControl(tl,name = con.lname(lr,fc.ear,i),colorId=18)
                jot = mc.createNode(ntc.tJoint,name=con.lname(lr,fc.ear,i,sc.sJot))
                jot_list.append(jot)
                mc.setAttr(jot+".radius",0.08)
                cr.scaleXYZ(ctr,0.1)
                mc.parent(jot,ctr,r=True)
                if lr  == fc.rt:
                    con.localMirror(ctr)
                
                if pat:
                    mc.parent(ctr,pat)
                con.emptyGroup(ctr)
                jgrp = con.emptyGroup(jot)
                mc.connectAttr(ctr+".t",jot+".t")
                mc.connectAttr(ctr+".r",jot+".r")
                mc.connectAttr(ctr+".s",jot+".s")
                if pat_j :
                    mc.parent(jgrp[0],pat_j)

                pat = ctr
                pat_j = jot
        mc.sets(jot_list,include=self.local_sets)
        return
    
if __name__ == '__main__':
    pass